<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>调试测试</title>
</head>
<body>
    <h1>调试测试</h1>
    <button onclick="testBasic()">测试基础功能</button>
    <button onclick="testOneFile()">测试单个文件</button>
    <div id="output"></div>

    <script src="dbc-parser.js"></script>
    <script>
        function log(msg) {
            document.getElementById('output').innerHTML += msg + '<br>';
        }
        
        function testBasic() {
            try {
                log('测试1: 检查DBCParser类是否存在...');
                if (typeof DBCParser === 'undefined') {
                    log('❌ DBCParser类未定义！');
                    return;
                }
                log('✅ DBCParser类存在');
                
                log('测试2: 检查DBCTokenizer类是否存在...');
                if (typeof DBCTokenizer === 'undefined') {
                    log('❌ DBCTokenizer类未定义！');
                    return;
                }
                log('✅ DBCTokenizer类存在');
                
                log('测试3: 创建tokenizer...');
                const simpleContent = `VERSION ""
BO_ 1 TestMessage: 8 TestNode
 SG_ TestSignal : 0|8@1+ (1,0) [0|255] "" TestNode`;
                log('内容: ' + simpleContent);
                
                const tokenizer = new DBCTokenizer(simpleContent);
                log('✅ Tokenizer创建成功');
                
                log('测试4: 创建parser...');
                const parser = new DBCParser(tokenizer);
                log('✅ Parser创建成功');
                
                log('测试5: 检查parse方法...');
                if (typeof parser.parse !== 'function') {
                    log('❌ parse方法不存在！');
                    return;
                }
                log('✅ parse方法存在');
                
                log('测试6: 开始解析...');
                const result = parser.parse();
                log('✅ 简单解析成功');
                log('结果: ' + JSON.stringify({
                    frames: result.frames ? result.frames.length : 'undefined',
                    warnings: result.warnings ? result.warnings.length : 'undefined'
                }));
                
            } catch (error) {
                log('❌ 错误: ' + error.message);
                log('错误栈: ' + error.stack);
                console.error(error);
            }
        }
        
        async function testOneFile() {
            try {
                log('测试文件加载...');
                const response = await fetch('./test.dbc');
                if (!response.ok) {
                    log('❌ 文件加载失败: ' + response.status);
                    return;
                }
                log('✅ 文件加载成功');
                
                const content = await response.text();
                log('文件大小: ' + content.length + ' 字符');
                
                const tokenizer = new DBCTokenizer(content);
                const parser = new DBCParser(tokenizer);
                const result = parser.parse();
                log('✅ 文件解析成功');
                log('帧数: ' + (result.frames ? result.frames.length : 'undefined'));
                log('详细结果: ' + JSON.stringify({
                    frames: result.frames ? result.frames.length : 0,
                    warnings: result.warnings ? result.warnings.length : 0,
                    version: result.version || 'unknown'
                }));
                
            } catch (error) {
                log('❌ 错误: ' + error.message);
                console.error(error);
            }
        }
    </script>
</body>
</html> 